class Solution
{
public:
    int minStoneSum(vector<int> &piles, int k)
    {
        priority_queue<int> pq;
        int result = 0;
        for (auto num : piles)
        {
            pq.push(num);
            result += num;
        }
        for (int i = 0; i < k; ++i)
        {
            int p = pq.top();
            pq.pop();
            result -= p / 2;
            p = (p + 1) / 2;
            pq.push(p);
        }
        return result;
    }
};